package com.zhen.gulimall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * spring boot 整合elasticsearch
 * 1、 导入依赖
 * 2、编写配置
 * 3、自动注入获得连接对象
 * 4、参照官网api操作elasticsearch
 */
@Configuration
public class GulimallElasticSearchConfig {

    @Bean
    RestHighLevelClient client() {
        RestClientBuilder builder = RestClient.builder(
                //new HttpHost("192.168.189.129", 9200, "http")
                new HttpHost("182.61.145.22", 9200, "http") //可以安装多个
        );
        return new RestHighLevelClient(builder);
    }

    public static final RequestOptions COMMON_OPTIONS;
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//        builder.addHeader("Authorization", "Bearer " + TOKEN);
//        builder.setHttpAsyncResponseConsumerFactory(
//                new HttpAsyncResponseConsumerFactory
//                        .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
        COMMON_OPTIONS = builder.build();
    }
}
